/*!
 * tykhome - notify.js
 * Author tykhome <yongketian@gmail.com>
 */

var models = require('../models');
var Notify = models.Notify;

var constants = require('../constants');

exports.newAndSave = function (type, from, to, message, callback) {
	var notify = new Notify();
	notify.type = type;
	notify.from = from;
	notify.to = to;
	notify.message = message;
	notify.save(callback);
};

/**
 * 查看
 * @param {String} soft_id softId
 * @param {Function} callback 回调函数
 */
exports.getSoftLostNotify = function (soft_id, callback) {
	Notify.findOne({
		type: constants.notify.type.SOFTLINKLOSE,
		message: soft_id
	}, callback);
};

/**
 * 查看当前用户的通知
 * @param {String} user_id uer id
 * @param {Function} callback 回调函数
 */
exports.getUserNotify = function (user_id, callback) {
	Notify.find({
		to: user_id
	}, callback);
}